package com.lmaos.basetools.timer;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
 * 
 * @author lmaos
 *
 * <p>作者：张星宇</p>
 * <p>时间：2017年6月20日 下午3:28:55</p>
 * <p>说明:基本定时任务配置数据		</p>
 *
 */
public class BaseTimerConfigGroup extends ArrayList<BaseTimerConfig>{

	private static final long serialVersionUID = 1L;
	private volatile Properties properties = null;
	
	public BaseTimerConfigGroup(String content) {
		super();
		this.content = content;
	}
	private String content;
	public void setContent(String content) {
		this.content = content;
	}
	public String getContent() {
		return content;
	}
	public Properties getProperties(){
		if(properties == null&&content!=null){
			try {
				properties = new Properties();
				properties.load(new StringReader(content));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return properties;
	}
	public BaseTimerConfigGroup getBaseTimerConfigByTag(String tag){
		BaseTimerConfigGroup baseTimerConfigs = new BaseTimerConfigGroup("");
		for (BaseTimerConfig baseTimerConfig : this) {
			if(tag.equals(baseTimerConfig.getTagName())){
				baseTimerConfigs.add(baseTimerConfig);
			}
		}
		return baseTimerConfigs;
	}
	public BaseTimerConfigGroup getBaseTimerConfigByAttrValue(String attrName,String attrValue){
		return getBaseTimerConfigByAttrValue(this, attrName, attrValue);
	}
	
	public BaseTimerConfigGroup getBaseTimerConfigByAttrValue(List<BaseTimerConfig> baseTimerConfigs_src,String attrName,String attrValue){
		BaseTimerConfigGroup baseTimerConfigs = new BaseTimerConfigGroup("");
		for (BaseTimerConfig baseTimerConfig : baseTimerConfigs_src) {
			if(attrValue.equals(baseTimerConfig.getString(attrName))){
				baseTimerConfigs.add(baseTimerConfig);
			}
		}
		return baseTimerConfigs;
	}
	public BaseTimerConfig getBaseTimerConfigById(String id){
		for (BaseTimerConfig baseTimerConfig : this) {
			if(id.equals(baseTimerConfig.getString("id"))){
				return baseTimerConfig;
			}
		}
		return null;
	}
}
